package server.business.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import server.business.mapper.TransfusionReviewMapper;
import server.business.pojo.TransfusionClinic;
import server.business.pojo.TransfusionReview;
import server.business.service.TransfusionClinicService;
import server.business.mapper.TransfusionClinicMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @author Galaxy
 * @description 针对表【transfusion_clinic】的数据库操作Service实现
 * @createDate 2022-11-08 12:46:25
 */
@Service("transfusionClinicService")
public class TransfusionClinicServiceImpl extends ServiceImpl<TransfusionClinicMapper, TransfusionClinic>
        implements TransfusionClinicService {
    @Autowired
    private TransfusionClinicMapper transfusionClinicMapper;
    @Autowired
    private TransfusionReviewMapper transfusionReviewMapper;

    /**
     * 申请临床输血
     * 
     * @param transfusionClinic
     */
    @Override
    public void tranClinicAdd(TransfusionClinic transfusionClinic) {
        transfusionClinicMapper.insert(transfusionClinic);
    }

    /**
     * 根据输血申请单号展示临床输血信息
     * 
     * @param transfusionNumber
     * @return
     */
    @Override
    public ArrayList<Object> getClinicInfo(String transfusionNumber) {
        return transfusionClinicMapper.showClinic(transfusionNumber);
    }

    /**
     * 批量删除
     * 
     * @param ids
     * @return
     */
    @Override
    public ArrayList<Long> selectId(ArrayList<Long> ids) {

        ArrayList<String> list = new ArrayList<>();
        for (Long id : ids) {
            QueryWrapper<TransfusionReview> queryWrapper = new QueryWrapper<>();
            System.out.println(id);
            queryWrapper.lambda().eq(TransfusionReview::getId, id);
            TransfusionReview t = transfusionReviewMapper.selectOne(queryWrapper);
            System.out.println(t.getTransfusionNumber());
            list.add(t.getTransfusionNumber());
            System.out.println(list);
        }

        ArrayList<Long> list1 = new ArrayList<>();
        for (String transfusionNumber : list) {
            QueryWrapper<TransfusionClinic> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.lambda().eq(TransfusionClinic::getTransfusionNumber, transfusionNumber);
            TransfusionClinic t1 = transfusionClinicMapper.selectOne(queryWrapper1);
            System.out.println(t1.getId());
            list1.add(t1.getId());
        }
        return list1;

    }

    // *************************************lrz*************************start
    @Override
    @SuppressWarnings("")
    public IPage<TransfusionClinic> getPage1(int currentPage, int pageSize, TransfusionClinic transfusionClinic) {
        LambdaQueryWrapper<TransfusionClinic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(Strings.isNotBlank(transfusionClinic.getTransfusionNumber()),
                        TransfusionClinic::getTransfusionNumber,
                        transfusionClinic.getTransfusionNumber())
                .eq(Strings.isNotBlank(transfusionClinic.getPatientIdcard()),
                        TransfusionClinic::getPatientIdcard, transfusionClinic.getPatientIdcard())
                .eq(Strings.isNotBlank(transfusionClinic.getTransfusionType()),
                        TransfusionClinic::getTransfusionType, transfusionClinic.getTransfusionType())
                .eq(Strings.isNotBlank(transfusionClinic.getTransfusionVolume()),
                        TransfusionClinic::getTransfusionVolume, transfusionClinic.getTransfusionVolume());
        IPage<TransfusionClinic> page = new Page<>(currentPage, pageSize);
        transfusionClinicMapper.selectPage(page, queryWrapper);
        return page;
    }
    // *************************************lrz*************************end
}
